<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.thymeleaf.org"
      layout:decorator="layout/m_master">

<div layout:fragment="content">
    <link href="/m/css/center/pay.css" rel="stylesheet"/>
    <div class="page-group">
        <div class="page page_pay">
            <div th:replace="layout/m_layout::title('订单支付')"></div>
            <div class="page-content">
                <div class="head">
                    <h3 class="money">¥ [[${setmeal.payAmount}]]</h3>
                    <p class="title" th:text="${setmeal.itemName}">
                    </p>
                </div>

                <div class="">
                    <div style="padding: .5rem .5rem; margin-top:2rem;">
                        <button class="btn btn-success btn-block submit">
                            支付完成
                        </button>
                    </div>

                    <div style="padding: .5rem .5rem;">
                        <button class="btn btn-invalid btn-block" onclick="window.history.go(-1)" type="submit">
                            取消支付
                        </button>
                    </div>
                </div>
                <script>
                    function onBridgeReady() {
                        WeixinJSBridge.invoke(
                            'getBrandWCPayRequest', {
                                "appId": "[[${appId}]]",     //公众号名称，由商户传入
                                "timeStamp": "[[${timeStamp}]]",         //时间戳，自1970年以来的秒数
                                "nonceStr": "[[${nonceStr}]]", //随机串
                                "package": "[[${package}]]",
                                "signType": "MD5",         //微信签名方式：
                                "paySign": "[[${sign}]]" //微信签名
                            },
                            function (res) {
                                if (res.err_msg == "get_brand_wcpay_request:ok") {
                                    // 使用以上方式判断前端返回,微信团队郑重提示：
                                    //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                                    alert("支付完成");
                                    window.location.href = "/m";
                                }
                            });
                    }

                    if (typeof WeixinJSBridge == "undefined") {
                        if (document.addEventListener) {
                            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                        } else if (document.attachEvent) {
                            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                        }
                    } else {
                        onBridgeReady();
                    }
                </script>
            </div>
        </div>
    </div>
    <div th:replace="layout/m_layout::systemJs"></div>
</div>
</html>

